package com.maomao.effective;

import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;

public class Test {
    public static void main(String[] args) {
        final Random random = new Random();
        User user1 = new User(1, 3, "xiao");
        User user2 = new User(1, 6, "xiao");
        User user3 = new User(1, 8, "xiao");
        User user4 = new User(1, 9, "xiao");
        User[] users = {user1, user2, user3, user4};
        Arrays.sort(users);
        for (User user : users) {
            System.out.println(user);
        }
        Map<String,String> a = new HashMap<>();
        a.put("xiao","min");

        for (int i = 0; i < users.length; ++i) {
            int j = random.nextInt(users.length);
            User user = users[i];
            users[i] = users[j];
            users[j] = user;
        }
        for (User user : users) {
            System.out.println(user);
        }
        List<User> userList = new ArrayList<>();
        userList.add(user1);
        userList.add(user2);
        userList.add(user4);
        userList.add(user3);
        List<Integer> ageList = userList.stream().map(User::getAge).collect(Collectors.toList());
        List<User> userList1 = userList.stream().filter(user -> user.getAge() == 6).collect(Collectors.toList());

        System.out.println(ageList);
        System.out.println(userList1);
        List<String> list = new ArrayList<>();
        list.add("xiao min");
        list.add("ai maomao");
        list.add("maomao ai");
        list = list.stream().map(s -> s.split(" ")).flatMap(Arrays::stream).collect(Collectors.toList());
        System.out.println(list);
    }
}
